*Figure A6: Yearly evolution of marginal effects evaluated at the yearly competitiveness level, and three yearly values of GPA*
clear all
use Clean_data, clear

by year: egen GPAp10=pctile(z_GPA), p(10)
by year: egen GPAp50=pctile(z_GPA), p(50)
by year: egen GPAp90=pctile(z_GPA), p(90)

********************************1.DROPOUT**********************
reg dropout i.year i.female##c.inv_competNOQUOTA c.z_GPA##i.female  c.z_GPA#c.inv_competNOQUOTA i.female#c.z_GPA#c.inv_competNOQUOTA if degree=="M"  & z_GPA!=. & foreign==0, robust

frame create orsCI_drop10 year or10 orlb10 orub10 Pval Gval10 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p10*
sum GPAp10 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval10`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval10`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval10`j'*Pval`j'
frame post orsCI_drop10 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval10`j')
}


frame create orsCI_drop50 year or50 orlb50 orub50 Pval Gval50 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp50 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval50`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval50`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval50`j'*Pval`j'
frame post orsCI_drop50 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval50`j')
}


frame create orsCI_drop90 year or90 orlb90 orub90 Pval Gval90 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp90 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval90`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval90`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval90`j'*Pval`j'
frame post orsCI_drop90 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval90`j')
}


frame change orsCI_drop10
frlink m:1 year, frame(orsCI_drop50)
frget or50 orlb50 orub50  Gval50, from(orsCI_drop50)

frlink m:1 year, frame(orsCI_drop90)
frget or90 orlb90 orub90  Gval90, from(orsCI_drop90)

*isid year, sort lcolor(black) lpattern(shortdash)
list, noobs clean 


*B-Graph*
		twoway	(rarea orub10 orlb10 year, fcolor(black%50) fintensity(inten50) lwidth(none) ) ///
(rarea orub50 orlb50 year, fcolor(gs6%50) fintensity(inten50) lwidth(none)) ///	
		(rarea orub90 orlb90 year, fcolor(gs12%50) fintensity(inten50) lwidth(none) ) ///
	(line or10 year, lcolor(gs0) lwidth(medthick) lpattern(shortdash_dot)) /// 
				(line or50 year, lcolor(gs5) lwidth(medthick)) /// 
		(line or90 year, lcolor(gs10) lwidth(medthick)  lpattern(shortdash)), /// 
	    graphregion(fcolor(white) lcolor(white)) ylab(,nogrid) ///
		  ytitle("Dropout") xtitle(" ") ///
	    yscale(titlegap(5)) ylabel(-0.035(0.005)0) xlabel(1983(6)2019, labsize(small)) ///
	    yline(0, lcolor(gray) lpattern(shortdash)) legend(off)
		
graph save "Dropout.gph", replace

frame change default 
********************************2.ANSWERED***********************************
reg z_answered i.female##c.inv_competNOQUOTA##c.z_GPA if degree=="M"  & z_GPA!=. & foreign==0, robust

frame create orsCI_answ10 year or10 orlb10 orub10 Pval Gval10 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p10*
sum GPAp10 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval10`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval10`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval10`j'*Pval`j'
frame post orsCI_answ10 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval10`j')
}


frame create orsCI_answ50 year or50 orlb50 orub50 Pval Gval50 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp50 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval50`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval50`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval50`j'*Pval`j'
frame post orsCI_answ50 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval50`j')
}


frame create orsCI_answ90 year or90 orlb90 orub90 Pval Gval90 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp90 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval90`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval90`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval90`j'*Pval`j'
frame post orsCI_answ90 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval90`j')
}

frame change orsCI_answ10
frlink m:1 year, frame(orsCI_answ50)
frget or50 orlb50 orub50  Gval50, from(orsCI_answ50)

frlink m:1 year, frame(orsCI_answ90)
frget or90 orlb90 orub90  Gval90, from(orsCI_answ90)

*isid year, sort
		
*Graph*
		twoway	(rarea orub10 orlb10 year, fcolor(black%50) fintensity(inten50) lwidth(none) ) ///
(rarea orub50 orlb50 year, fcolor(gs6%50) fintensity(inten50) lwidth(none)) ///	
		(rarea orub90 orlb90 year, fcolor(gs12%50) fintensity(inten50) lwidth(none) ) ///
	(line or10 year, lcolor(gs0) lwidth(medthick) lpattern(shortdash_dot)) /// 
				(line or50 year, lcolor(gs5) lwidth(medthick)) /// 
		(line or90 year, lcolor(gs10) lwidth(medthick)  lpattern(shortdash)), /// 
	    graphregion(fcolor(white) lcolor(white)) ylab(,nogrid) ///
		  ytitle("Answered") xtitle(" ") ///
	    yscale(titlegap(5)) ylabel(-0.082(0.025)0.055) xlabel(1983(6)2019, labsize(small)) ///
	    yline(0, lcolor(gray) lpattern(shortdash)) legend(off)
		
graph save "Answered.gph", replace
frame change default

***************************3. TEST CORRECT**********************
		
reg z_test_correct i.female##c.inv_competNOQUOTA##c.z_GPA if degree=="M"  & z_GPA!=. & foreign==0, robust

frame create orsCI_corr10 year or10 orlb10 orub10 Pval Gval10 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p10*
sum GPAp10 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval10`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval10`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval10`j'*Pval`j'
frame post orsCI_corr10 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval10`j')
}


frame create orsCI_corr50 year or50 orlb50 orub50 Pval Gval50 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp50 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval50`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval50`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval50`j'*Pval`j'
frame post orsCI_corr50 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval50`j')
}


frame create orsCI_corr90 year or90 orlb90 orub90 Pval Gval90 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp90 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval90`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval90`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval90`j'*Pval`j'
frame post orsCI_corr90 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval90`j')
}


frame change orsCI_corr10
frlink m:1 year, frame(orsCI_corr50)
frget or50 orlb50 orub50  Gval50, from(orsCI_corr50)

frlink m:1 year, frame(orsCI_corr90)
frget or90 orlb90 orub90  Gval90, from(orsCI_corr90)

*isid year, sort
list, noobs clean 

*Graph*

twoway	(rarea orub10 orlb10 year, fcolor(black%50) fintensity(inten50) lwidth(none) ) ///
(rarea orub50 orlb50 year, fcolor(gs6%50) fintensity(inten50) lwidth(none)) ///	
		(rarea orub90 orlb90 year, fcolor(gs12%50) fintensity(inten50) lwidth(none) ) ///
	(line or10 year, lcolor(gs0) lwidth(medthick) lpattern(shortdash_dot)) /// 
				(line or50 year, lcolor(gs5) lwidth(medthick)) /// 
		(line or90 year, lcolor(gs10) lwidth(medthick)  lpattern(shortdash)), /// 
	    graphregion(fcolor(white) lcolor(white)) ylab(,nogrid) ///
		  ytitle("Test Correct") xtitle(" ",size(small))  ///
	    yscale(titlegap(5)) ylabel(-0.18(0.1)0.14) xlabel(1983(6)2019, labsize(small)) ///
	    yline(0, lcolor(gray) lpattern(shortdash)) legend(off)
		
graph save "TestCorrect.gph", replace
frame change default

***************************4. TEST POINTS**********************
reg z_test_points i.female##c.inv_competNOQUOTA##c.z_GPA if degree=="M"  & z_GPA!=. & foreign==0, robust

frame create orsCI_test10 year or10 orlb10 orub10 Pval Gval10 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p10*
sum GPAp10 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval10`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval10`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval10`j'*Pval`j'
frame post orsCI_test10 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval10`j')
}


frame create orsCI_test50 year or50 orlb50 orub50 Pval Gval50 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp50 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval50`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval50`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval50`j'*Pval`j'
frame post orsCI_test50 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval50`j')
}


frame create orsCI_test90 year or90 orlb90 orub90 Pval Gval90 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp90 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval90`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval90`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval90`j'*Pval`j'
frame post orsCI_test90 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval90`j')
}

frame change orsCI_test10
frlink m:1 year, frame(orsCI_test50)
frget or50 orlb50 orub50  Gval50, from(orsCI_test50)

frlink m:1 year, frame(orsCI_test90)
frget or90 orlb90 orub90  Gval90, from(orsCI_test90)

*isid year, sort
list, noobs clean 

		
*B-Graph*
		twoway	(rarea orub10 orlb10 year, fcolor(black%50) fintensity(inten50) lwidth(none) ) ///
(rarea orub50 orlb50 year, fcolor(gs6%50) fintensity(inten50) lwidth(none)) ///	
		(rarea orub90 orlb90 year, fcolor(gs12%50) fintensity(inten50) lwidth(none) ) ///
	(line or10 year, lcolor(gs0) lwidth(medthick) lpattern(shortdash_dot)) /// 
				(line or50 year, lcolor(gs5) lwidth(medthick)) /// 
		(line or90 year, lcolor(gs10) lwidth(medthick)  lpattern(shortdash)), /// 
	    graphregion(fcolor(white) lcolor(white)) ylab(,nogrid) ///
		  ytitle("Test Points") xtitle(" ",size(small))  ///
	    yscale(titlegap(5)) ylabel(-0.185 (0.1)0.205) xlabel(1983(6)2019, labsize(small)) ///
	    yline(0, lcolor(gray) lpattern(shortdash)) legend(off)
		
graph save "TestPoints.gph", replace
frame change default


********************5.TOTAL POINTS****************************
reg z_total_points i.female##c.inv_competNOQUOTA##c.z_GPA if degree=="M"  & z_GPA!=. & foreign==0, robust

frame create orsCI_total10 year or10 orlb10 orub10 Pval Gval10 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p10*
sum GPAp10 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval10`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval10`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval10`j'*Pval`j'
frame post orsCI_total10 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval10`j')
}


frame create orsCI_total50 year or50 orlb50 orub50 Pval Gval50 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp50 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval50`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval50`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval50`j'*Pval`j'
frame post orsCI_total50 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval50`j')
}


frame create orsCI_total90 year or90 orlb90 orub90 Pval Gval90 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp90 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval90`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval90`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval90`j'*Pval`j'
frame post orsCI_total90 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval90`j')
}

frame change orsCI_total10
frlink m:1 year, frame(orsCI_total50)
frget or50 orlb50 orub50  Gval50, from(orsCI_total50)

frlink m:1 year, frame(orsCI_total90)
frget or90 orlb90 orub90  Gval90, from(orsCI_total90)

*isid year, sort
list, noobs clean 

*Graph*
twoway	(rarea orub10 orlb10 year, fcolor(black%50) fintensity(inten50) lwidth(none) ) ///
(rarea orub50 orlb50 year, fcolor(gs6%50) fintensity(inten50) lwidth(none)) ///	
		(rarea orub90 orlb90 year, fcolor(gs12%50) fintensity(inten50) lwidth(none) ) ///
	(line or10 year, lcolor(gs0) lwidth(medthick) lpattern(shortdash_dot)) /// 
				(line or50 year, lcolor(gs5) lwidth(medthick)) /// 
		(line or90 year, lcolor(gs10) lwidth(medthick)  lpattern(shortdash)), /// 
	    graphregion(fcolor(white) lcolor(white)) ylab(,nogrid) ///
		  ytitle("Total Points") xtitle(" ",size(small))  ///
	    yscale(titlegap(5)) ylabel(-0.185(0.1)0.19) xlabel(1983(6)2019, labsize(small)) ///
	    yline(0, lcolor(gray) lpattern(shortdash)) legend(off)
		
graph save "TotalPoints.gph", replace
frame change default

********************************6.POSITION ****************************
reg position i.female##c.inv_competNOQUOTA c.z_GPA##i.female  c.z_GPA#c.inv_competNOQUOTA i.female#c.z_GPA#c.inv_competNOQUOTA if degree=="M" & foreign==0 & GPA!=. & test==1  ,robust 


frame create orsCI_posit10 year or10 orlb10 orub10 Pval Gval10 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p10*
sum GPAp10 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval10`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval10`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval10`j'*Pval`j'
frame post orsCI_posit10 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval10`j')
}


frame create orsCI_posit50 year or50 orlb50 orub50 Pval Gval50 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp50 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval50`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval50`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval50`j'*Pval`j'
frame post orsCI_posit50 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval50`j')
}


frame create orsCI_posit90 year or90 orlb90 orub90 Pval Gval90 
forvalues j=1983/2019{
sum inv_competNOQUOTA if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Pval`j'=r(mean)
*p50*
sum GPAp90 if year==`j' & degree=="M"  & z_GPA!=. & foreign==0
scalar Gval90`j'=r(mean)
lincom _b[1.female] + _b[1.female#c.z_GPA]*Gval90`j' + _b[1.female#c.inv_competNOQUOTA]*Pval`j' + _b[1.female#c.z_GPA#c.inv_competNOQUOTA]*Gval90`j'*Pval`j'
frame post orsCI_posit90 (`j') (`r(estimate)') (`r(lb)') (`r(ub)') (Pval`j') (Gval90`j')
}


frame change orsCI_posit10
frlink m:1 year, frame(orsCI_posit50)
frget or50 orlb50 orub50  Gval50, from(orsCI_posit50)

frlink m:1 year, frame(orsCI_posit90)
frget or90 orlb90 orub90  Gval90, from(orsCI_posit90)

*isid year, sort
list, noobs clean 
*Graph*
twoway	(rarea orub10 orlb10 year, fcolor(black%50) fintensity(inten50) lwidth(none) ) ///
(rarea orub50 orlb50 year, fcolor(gs6%50) fintensity(inten50) lwidth(none)) ///	
		(rarea orub90 orlb90 year, fcolor(gs12%50) fintensity(inten50) lwidth(none) ) ///
	(line or10 year, lcolor(gs0) lwidth(medthick) lpattern(shortdash_dot)) /// 
				(line or50 year, lcolor(gs5) lwidth(medthick)) /// 
		(line or90 year, lcolor(gs10) lwidth(medthick)  lpattern(shortdash)), /// 
	    graphregion(fcolor(white) lcolor(white)) ylab(,nogrid) ///
		  ytitle("Position") xtitle(" ",size(small))  ///
	    yscale(titlegap(5)) ylabel(-0.065(0.05)0.105) xlabel(1983(6)2019, labsize(small)) ///
	    yline(0, lcolor(gray) lpattern(shortdash)) legend(off)
		
graph save "Position.gph", replace
frame change default



***COMBINE ALL GRAPHS***
graph combine Dropout.gph Answered.gph TestCorrect.gph TestPoints.gph TotalPoints.gph Position.gph, graphregion(color(white)) cols(2) ysize(11.7) xsize(8.3)
